﻿var oEditor = window.parent.InnerDialogLoaded();
var FCK = oEditor.FCK;
var FCKLang = oEditor.FCKLang;
var FCKConfig = oEditor.FCKConfig;
var oFakeImage = FCK.Selection.GetSelectedElement();
var oEmbed;
if(oFakeImage) {
	if(oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckmedia'))
		oEmbed = FCK.GetRealElement(oFakeImage);
	else
		oFakeImage = null;
}
window.onload = function() {
	oEditor.FCKLanguageManager.TranslatePage(document);
	LoadSelection();
	window.parent.SetAutoSize(true);
	window.parent.SetOkButton(true);
}
function LoadSelection() {
	if(!oEmbed) return;
	var sUrl = GetAttribute(oEmbed, 'src', '');
	GetE('txtUrl').value = GetAttribute( oEmbed, 'src', '');
	GetE('txtWidth').value = GetAttribute( oEmbed, 'width', '');
	GetE('txtHeight').value = GetAttribute( oEmbed, 'height', '');
}
function Ok() {
	if(GetE('txtUrl').value.length == 0) {
		GetE('txtUrl').focus();
		alert(oEditor.FCKLang.DlgAlertUrl);
		return false;
	}
	if(!oEmbed) {
		oEmbed = FCK.EditorDocument.createElement('EMBED');
		oFakeImage = null;
	}
	UpdateEmbed(oEmbed);
	if(!oFakeImage)	{
		oFakeImage = oEditor.FCKDocumentProcessor_CreateFakeImage('FCK__Media', oEmbed);
		oFakeImage.setAttribute('_fckmedia', 'true', 0);
		oFakeImage = FCK.InsertElementAndGetIt(oFakeImage);
	} else
		oEditor.FCKUndo.SaveUndoStep();
	oEditor.FCKMediaProcessor.RefreshView(oFakeImage, oEmbed);
	return true;
}
function UpdateEmbed(e) {
	e.src = GetE('txtUrl').value;
	SetAttribute( e, "width" , GetE('txtWidth').value);
	SetAttribute( e, "height", GetE('txtHeight').value);
}